/*
 * Copyright 2008 Andrej Herich
 * 
 * http://azetclient.yw.sk/
 * http://azetclient.googlecode.com/
 * 
 * This file is part of AzetClient.
 * 
 * AzetClient is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * AzetClient is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with AzetClient.  If not, see <http://www.gnu.org/licenses/>.
 */

package sk.yw.azetclient.gui;

import java.awt.MenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import org.apache.log4j.Logger;
import sk.yw.azetclient.Main;

/**
 *
 * @author error216
 */
public class ChangeMainFrameVisibilityMenuItem extends MenuItem
        implements ActionListener, WindowListener{
    
    private static final long serialVersionUID = 2627812162l;
    
    private static final Logger logger =
            Logger.getLogger(ChangeMainFrameVisibilityMenuItem.class);
    
    public ChangeMainFrameVisibilityMenuItem(boolean visible) {
        super();
        addActionListener(this);
        changeVisibility(visible);
    }
    
    private void changeVisibility(boolean visible) {
        if (visible) {
            logger.debug("Setting main frame visibility to visible");
            setLabel(Main.getText("hideMainFrame"));
        } else {
            logger.debug("Setting main frame visibility to invisible");
            setLabel(Main.getText("showMainFrame"));
        }
    }

    public void actionPerformed(ActionEvent e) {
        MainFrame mainFrame = Main.getMainFrame();
        mainFrame.setVisible(!mainFrame.isVisible());
        changeVisibility(mainFrame.isVisible());
    }

    public void windowOpened(WindowEvent e) {
    }

    public void windowClosing(WindowEvent e) {
        changeVisibility(false);
    }

    public void windowClosed(WindowEvent e) {
    }

    public void windowIconified(WindowEvent e) {
    }

    public void windowDeiconified(WindowEvent e) {
    }

    public void windowActivated(WindowEvent e) {
    }

    public void windowDeactivated(WindowEvent e) {
    }

}
